package com.litblue.api.config;


import com.litblue.api.fallback.GetArtWorkClientFallbackFactory;
import com.litblue.api.fallback.GetUserInfoClientFallbackFactory;
import com.litblue.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;


public class DefaultFeignConfig {

    @Bean
    public GetArtWorkClientFallbackFactory getArtWorkClientFallbackFactory() {
        return new GetArtWorkClientFallbackFactory();
    }
    @Bean
    public GetUserInfoClientFallbackFactory getUserInfoClientFallbackFactory() {
        return new GetUserInfoClientFallbackFactory();
    }

    @Bean
    public RequestInterceptor requestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                Long userId = UserContext.getUser();
                if (userId != null) {
                    template.header("user-info",userId.toString());
                }
            }
        };
    }
}